// 基础游戏对象
const canvas = wx.createCanvas()
const system = wx.getSystemInfoSync()

// 设置画布尺寸
canvas.width = system.windowWidth
canvas.height = system.windowHeight

const ctx = canvas.getContext('2d')

// 创建基础对象
const requestAnimationFrame = (callback) => {
  return setTimeout(callback, 1000 / 60)
}

const cancelAnimationFrame = (id) => {
  clearTimeout(id)
}

// 添加requestAnimationFrame兼容
if (!wx.requestAnimationFrame) {
  wx.requestAnimationFrame = function(callback) {
    return setTimeout(callback, 1000 / 60);
  };
}

if (!wx.cancelAnimationFrame) {
  wx.cancelAnimationFrame = function(id) {
    clearTimeout(id);
  };
}

// 扩展 GameGlobal
Object.assign(GameGlobal, {
  canvas,
  ctx,
  requestAnimationFrame,
  cancelAnimationFrame,
  Image: wx.createImage
})

// 导出所需的对象和方法
export {
  canvas,
  ctx,
  requestAnimationFrame,
  cancelAnimationFrame
}

// 为了兼容性，导出一个模拟的 window 对象
export default {
  canvas,
  requestAnimationFrame,
  cancelAnimationFrame,
  setTimeout,
  setInterval,
  clearTimeout,
  clearInterval,
  Image: wx.createImage
} 